import java.util.Arrays;
import java.util.Scanner;

/**
 * 【程序28】   
 * 题目：对10个数进行排序 
 */
public class test28 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array1 = new int[10];
        System.out.print("请依次输入10个数：");
        for (int i = 0; i < 10; i++) {
            array1[i] = sc.nextInt();
        }
        System.out.println("原数组为：" + Arrays.toString(array1));
        System.out.print("请选择排序or冒泡排序or插入排序（1、2、3）：");
        int choice = sc.nextInt();
        if (choice == 1)
            System.out.println(Arrays.toString(selectSort(array1)));
        else if (choice == 2)
            System.out.println(Arrays.toString(bubbleSort(array1)));
        else
            System.out.println(Arrays.toString(insertSort(array1)));
    }

    public static int[] selectSort(int[] array) {
        int temp;
        for (int i = 0; i < 9; i++) {
            for (int j = i + 1; j < 10; j++) {
                if (array[j] <= array[i]) {
                    temp = array[i];
                    array[i] = array[j];
                    array[j] = temp;
                }
            }
        }
        return array;
    }

    public static int[] bubbleSort(int[] array) {
        int temp;
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9 - i; j++) {
                if (array[j] > array[j + 1]) {
                    temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
        return array;
    }

    public static int[] insertSort(int[] array) {
        int temp;
        int j;
        for (int i = 1; i < 10; i++) {
            temp = array[i];
            for (j = i - 1; j >= 0 && temp < array[j]; j--) {
                array[j + 1] = array[j];
            }
            array[j + 1] = temp;
        }
        return array;
    }
}
